# -*- coding: utf-8 -*-
'''
Created on 2010-10-11

@author: tongji@rekoo.com
'''

import logging

logging.basicConfig(format='%(asctime)s\t%(message)s',
                    filename='D:/logs/statistics.log',
                    datefmt='%H:%M:%S',                    
                    filemode='a',
                    level=logging.NOTSET)

logging.getLogger()
logging.info('Hello, world!')

class Singleton(type):
    '''this is a meta class for Singleton'''
    def __init__(cls, name, bases, dic):
        super(Singleton, cls).__init__(name, bases, dic)
        cls.instance = None
    
    def __call__(cls, *args, **kwargs):
        if cls.instance is None:
            cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
        return cls.instance

class Logger(object):
    __metaclass__ = Singleton
    '''for logging message'''
    def __init__(self, filename='./statistics.log'):
        if filename is None:
            raise 'please specify the filename with the path'
        logging.basicConfig(format='%(asctime)s\t%(message)s', 
                            filename=filename, 
                            datefmt='%H:%M:%S',
                            level=logging.NOTSET)
        logging.getLogger()
        self.logging = logging
        self.formatter = ['uid', 'scene', 'level', 'stay', 'action', 'v1', 'v2', 'v3', 'v4', 'num'] # 日志标准格式
        self.message = ''
        
    def set_filename(self, filename):
        '''reset the log file name'''
        self.filename = filename
    
    def set_data(self, data):
        self.data = data
    
    def log(self):
        '''写入日志记录'''
        if self.message:
            self.log(self.message)
    
    
